# 我们把变量从内存中变成可存储或传输的过程称之为序列化
# 反之,我们称之为反序列化

import json


class A:
    def __init__(self, name, age):
        self.name = name
        self.age = age

    def run(self):
        print('run......')


a = A('zhangsan', 18)


def change(a):
    dict1 = {
        'name': a.name,
        'age': a.age
    }
    return dict1


str1 = json.dumps(a, default=change)
print(str1)


def dict2a(d):
    return A(d['name'], d['age'])


a = json.loads(str1)
print(a)
print(dict2a(a))
